from django.core.cache import caches


def cache_check(**cache_kwargs):
    def _cache_check(func):
        def wrapper(self,request ,*args, **kwargs):

            # 自定义缓存key
            CACHE=caches["default"]
            if "cache" in cache_kwargs:
                CACHE=caches[cache_kwargs["cache"]]
            key=cache_kwargs["key_prefix"] + str(kwargs["sku_id"])+cache_kwargs["key_param"]
            if CACHE.get(key):
                print("----redis----")
                return CACHE.get(key)
            value=func(self,request,*args, **kwargs)
            expires= cache_kwargs.get("expires", 60)
            CACHE.set(key,value,expires)

            return value
        return wrapper
    return _cache_check